<?php

namespace App\Admin\Controllers;

use App\Models\Order;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class OrdersController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '订单管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Order);

        $grid->column('id', __('Id'));
        $grid->column('user.username', __('用户名'));
        $grid->column('machine.name', __('商品名称'));

        $grid->column('price', __('价格'));
        $grid->column('total_price', __('总价'));
     //   $grid->column('total_electricity_fee', __('总电费'));
        //$grid->column('total_income', __('总收益'));
        $grid->column('created_at', __('创建时间'));
      //  $grid->column('updated_at', __('修改时间'));
        $grid->column('status', __('状态'))->display(function ($status) {
            return config('conf.orders_status')[$status];
        });
        $grid->disableCreateButton();
        $grid->actions(function ($actions) {
            $actions->disableDelete();
            $actions->disableView();
        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Order::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('user_id', __('User id'));
        $show->field('machine_id', __('Machine id'));
  //      $show->field('computing', __('Computing'));
        $show->field('price', __('Price'));
   //     $show->field('total_price', __('Total price'));
     //   $show->field('total_electricity_fee', __('Total electricity fee'));
     //   $show->field('total_income', __('Total income'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Order);
        $form->timestamps = false;
        $form->number('user_id', __('用户名'));
        $form->number('machine_id', __('商品名称'));
    //    $form->number('computing', __('算力'));
        $form->decimal('price', __('\价格'));
        $form->decimal('total_price', __('总价格'));
      //  $form->decimal('total_electricity_fee', __('总电费'));
      ///  $form->decimal('total_income', __('总收益'));
        $form->select('status', __('状态'))->options(config('conf.orders'));
        return $form;
    }
}
